package com.lhz.common.page;


import com.lhz.common.constant.ResponseState;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * Created by LiGezZ
 * Date on 2021/4/15 15:16
 *
 * @author LiGezZ
 */
@Data
public class ResponseObject {

    @Schema(description = "信息")
    private String msg;

    @Schema(description = "响应码")
    private int code;

    @Schema(description = "数据")
    private Object data;

    public static ResponseObject successPost() {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg("成功添加数据");
        return responseObject;
    }

    public static ResponseObject successUpdate() {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg("成功修改数据");
        return responseObject;
    }

    public static ResponseObject successDel() {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg("成功删除数据");
        return responseObject;
    }


    public static ResponseObject success(Object object) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(object);
        responseObject.setCode(200);
        responseObject.setMsg("操作成功");
        return responseObject;
    }

    public static ResponseObject success(String msg) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg(msg);
        return responseObject;
    }

    public static ResponseObject success() {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg("操作成功");
        return responseObject;
    }

    public static ResponseObject success(Object object, String msg) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(object);
        responseObject.setCode(200);
        responseObject.setMsg(msg);
        return responseObject;
    }

    public static ResponseObject fail(Object data, String msg) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(data);
        responseObject.setCode(500);
        responseObject.setMsg(msg);
        return responseObject;
    }

    public static ResponseObject fail(String msg) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(400);
        responseObject.setMsg(msg);
        return responseObject;
    }

    public static ResponseObject fail() {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(400);
        responseObject.setMsg("操作失败");
        return responseObject;
    }

    public static ResponseObject fail(String msg, int code) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(code);
        responseObject.setMsg(msg);
        return responseObject;
    }

    public static ResponseObject fail(ResponseState e) {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setCode(e.getCode());
        responseObject.setMsg(e.getName());
        return responseObject;
    }
}
